# -*- coding: utf-8 -*-
# @Date    : 2022-01-20 23:04:06
# @Author  : BrightSoul (653538096@qq.com)


import os
import time
from PIL import Image


# in_path = "../_data/d"
# out_path = "../_data/l"
in_path = "../../_data/img"
out_path = "../../_data/img_small"
start_time = time.time()


def resizeImgs(in_path,out_path,h=180):
    if not os.path.exists(out_path):
        os.makedirs(out_path)

    imgNameL = os.listdir(in_path)
    for imgName in imgNameL:
        img = Image.open(os.path.join(in_path,imgName))
        width = int(img.size[0]*h/img.size[1])
        height = h
        img = img.resize((width, height), Image.ANTIALIAS)
        img.save(os.path.join(out_path,imgName))
        print("[{:.2f}] {} done".format(time.time()-start_time,imgName))


if __name__ == '__main__':
    resizeImgs(in_path,out_path)
